home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_068 / mg1b / tty / amiga / ttymouse.c < prev   
C/C++ Source or Header  |  1992-05-06  |  5KB  |  279 lines

  1. /*
  2.  * Name:    MicroEmacs
  3.  *        Commodore Amiga mouse handling (no longer simple!)
  4.  * Version:    Gnu v30
  5.  * Last edit:    02-Aug-86  ...!ihnp4!seismo!ut-sally!ut-ngp!mic
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #undef    TRUE
  11. #undef    FALSE
  12. #include "def.h"
  13.  
  14. extern    int    ttmouse();        /* Defined by "ttyio.c"        */
  15. extern    int    forwline();        /* Defined by "line.c"        */
  16. extern    int    forwchar();        /* Defined by "basic.c"        */
  17. extern    int    setmark();        /* Defined by "basic.c"        */
  18. extern    int    isetmark();        /* Defined by "basic.c"        */
  19.  
  20. /* stuff for go-to-window-and-do-it functions */
  21. extern    int    reposition();
  22. extern    int    delfword();
  23. extern    int    killline();
  24. extern    int    forwdel();
  25. extern    int    justone();
  26. extern    int    killregion();
  27. extern    int    yank();
  28. extern    int    forwpage();
  29. extern    int    backpage();
  30. extern    int    splitwind();
  31. extern    int    delwind();
  32. extern    int    gotobob();
  33. extern    int    gotoeob();
  34. extern    int    enlargewind();
  35. extern    int    shrinkwind();
  36.  
  37. /*
  38.  * Handle the mouse click that's been passed
  39.  * by ttgetc() and position dot where the
  40.  * user pointed at.  If this is the same position
  41.  * where the user pointed the last time, set the mark,
  42.  * whether or not this is a true double-click.
  43.  * This isn't a true double-click, but it does
  44.  * most of what we want.
  45.  */
  46.  
  47. static USHORT    oldrow = HUGE, oldcol = HUGE;    /* last mouse click    */
  48. static USHORT    newrow, newcol;            /* next mouse click    */
  49.  
  50. amigamouse(f, n, k)
  51. {
  52.     if (!dottomouse())            /* sets newrow, newcol    */
  53.         return (FALSE);
  54.     if ((newrow == oldrow) && (newcol == oldcol))
  55.         setmark(FALSE, 0, KRANDOM);    /* double-click        */
  56.     oldrow = newrow;                /* save state        */
  57.     oldcol = newcol;
  58.     return (TRUE);
  59. }
  60.  
  61. /*
  62.  * Recenter on selected line
  63.  */
  64. mreposition(f, n, k)
  65. {
  66.     if (!dottomouse())
  67.         return (FALSE);
  68.     return (reposition(f, n, k));
  69. }
  70.  
  71. /*
  72.  * Delete word after selected char
  73.  */
  74. mdelfword(f, n, k)
  75. {
  76.     if (!dottomouse())
  77.         return (FALSE);
  78.     return (delfword(f, n, k));
  79. }
  80.  
  81. /*
  82.  * Move to selection, kill line
  83.  */
  84. mkillline(f, n, k)
  85. {
  86.     if (!dottomouse())
  87.         return (FALSE);
  88.     return (killline(f, n, k));
  89. }
  90.  
  91. /*
  92.  * Move to selection, kill line
  93.  */
  94. mforwdel(f, n, k)
  95. {
  96.     if (!dottomouse())
  97.         return (FALSE);
  98.     return (forwdel(f, n, k));
  99. }
  100.  
  101. /*
  102.  * Move to selection, kill line
  103.  */
  104. mdelwhite(f, n, k)
  105. {
  106.     if (!dottomouse())
  107.         return (FALSE);
  108.     return (justone(f, n, k));
  109. }
  110.  
  111. /*
  112.  * Set mark, move to selection, kill region.
  113.  */
  114. mkillregion(f, n, k)
  115. {
  116.     register struct LINE *p_old;
  117.     register short    o_old;
  118.  
  119.     p_old = curwp->w_markp;        /* Save old mark */
  120.     o_old = curwp->w_marko;
  121.     isetmark();                /* and set current one */
  122.     if (!dottomouse()) {
  123.         curwp->w_markp = p_old;    /* Oops - put mark back */
  124.         curwp->w_marko = o_old;
  125.         return (FALSE);
  126.         }
  127.     return (killregion(f, n, k));
  128. }
  129.  
  130. /*
  131.  * Move to selection, yank kill buffer
  132.  */
  133. myank(f, n, k)
  134. {
  135.     if (!dottomouse())
  136.         return (FALSE);
  137.     return (yank(f, n, k));
  138. }
  139.  
  140. /*
  141.  * Select window pointed to by mouse, then scroll down
  142.  */
  143.  
  144. mforwpage(f, n, k)
  145. {
  146.     if (!dottomouse())
  147.         return (FALSE);
  148.     return (forwpage(f, n, k));
  149. }
  150.  
  151. /*
  152.  * Select buffer, scroll page down
  153.  */
  154. mbackpage(f, n, k)
  155. {
  156.     if (!dottomouse())
  157.         return (FALSE);
  158.     return (backpage(f, n, k));
  159. }
  160.  
  161. /*
  162.  * Select the window, split it.
  163.  */
  164. msplitwind(f, n, k)
  165. {
  166.     if (!dottomouse())
  167.         return (FALSE);
  168.     return (splitwind(f, n, k));
  169. }
  170.  
  171. /*
  172.  * Select the buffer, delete it.
  173.  */
  174. mdelwind(f, n, k)
  175. {
  176.     if (!dottomouse())
  177.         return (FALSE);
  178.     return (delwind(f, n, k));
  179. }
  180.  
  181. /*
  182.  * Select window, goto beginning of buffer
  183.  */
  184. mgotobob(f, n, k)
  185. {
  186.     if (!dottomouse())
  187.         return (FALSE);
  188.     return (gotobob(f, n, k));
  189. }
  190.  
  191. /*
  192.  * Select window, go to end of buffer
  193.  */
  194. mgotoeob(f, n, k)
  195. {
  196.     if (!dottomouse())
  197.         return (FALSE);
  198.     return (gotoeob(f, n, k));
  199. }
  200.  
  201. /*
  202.  * Select window, enlarge it.
  203.  */
  204. menlargewind(f, n, k)
  205. {
  206.     if (!dottomouse())
  207.         return (FALSE);
  208.     return (enlargewind(f, n, k));
  209. }
  210.     
  211. /*
  212.  * Select window, shrink it.
  213.  */
  214. mshrinkwind(f, n, k)
  215. {
  216.     if (!dottomouse())
  217.         return (FALSE);
  218.     return (shrinkwind(f, n, k));
  219. }
  220.  
  221. /*
  222.  * Utility routine to move dot to where
  223.  * the user clicked.  If in mode line,
  224.  * chooses that buffer as the one
  225.  * to work on.
  226.  */
  227.  
  228. static dottomouse()
  229. {
  230.     register WINDOW *wp;
  231.     register int    dot;
  232.     register int    c;
  233.     register int    col;
  234.     int        qualifier;
  235.  
  236.     /* figure out new screen position of dot, throw away mouse evt */
  237.     if (!ttmouse(TRUE, &newrow, &newcol, &qualifier))
  238.         return (FALSE);            /* out of synch!    */
  239.  
  240.     /* find out which window was clicked in                */
  241.     for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
  242.         if ((newrow >= wp->w_toprow) && 
  243.             (newrow <= (wp->w_toprow + wp->w_ntrows)))
  244.             break;
  245.  
  246.     if (wp == NULL)                /* echo line        */
  247.         return (ABORT);
  248.     else if (newrow == wp->w_toprow + wp->w_ntrows) {/* mode line */
  249.         curwp = wp;            /* just change buffer     */
  250.         curbp = wp->w_bufp;
  251.     } else {
  252.         /* move to selected window, move dot to top left    */
  253.         curwp = wp;
  254.         curbp = wp->w_bufp;
  255.         curwp->w_dotp = wp->w_linep;
  256.         curwp->w_doto = 0;
  257.  
  258.         /* go forward the correct # of lines         */
  259.         forwline(FALSE, newrow - curwp->w_toprow, KRANDOM);
  260.     
  261.         /* go forward the correct # of characters    */
  262.         /* need to count them out because of tabs    */
  263.         col = dot = 0;
  264.         while ((col < newcol) && (dot < llength(curwp->w_dotp))) {
  265.             c = lgetc(curwp->w_dotp, dot++);
  266.             if (c == '\t')
  267.                 col |= 0x07;
  268.             else if (ISCTRL(c) != FALSE)
  269.                 ++col;
  270.             ++col;
  271.         }
  272. #ifdef        MEYN
  273.         if (col > newcol) dot--;    /* back up to tab/ctrl char */
  274. #endif
  275.         forwchar(FALSE, dot, KRANDOM);
  276.     }
  277.     return (TRUE);
  278. }
  279.